package com.zhouheng.springbootdesignpattern.proxypattern.cglibproxy;

import com.zhouheng.springbootdesignpattern.proxypattern.jdkdynamicproxy.IStudentDao;
import com.zhouheng.springbootdesignpattern.proxypattern.jdkdynamicproxy.StudentDaoImpl;
import com.zhouheng.springbootdesignpattern.proxypattern.staticproxy.IUserDao;
import com.zhouheng.springbootdesignpattern.proxypattern.staticproxy.UserDaoImpl;

/**
 * 测试Cglib代理
 *
 * @author 周恒
 * @date 20200120 14:38:15
 * @since v1.0
 */
public class TestCglibProxy {

    public static void main(String[] args) {
        testUserDao();
        testStudentDao();
        testTeacherDao();
    }

    private static void testUserDao() {
        //目标对象
        IUserDao target = new UserDaoImpl();
        //代理对象
        IUserDao proxy = (UserDaoImpl) new ProxyFactory(target).getProxyInstance();
        //执行代理对象的方法
        proxy.save();
    }

    private static void testStudentDao() {
        //目标对象
        IStudentDao target = new StudentDaoImpl();
        //代理对象
        IStudentDao proxy = (StudentDaoImpl) new ProxyFactory(target).getProxyInstance();
        //执行代理对象的方法
        proxy.save("小欣", 27);
        proxy.update("小赵");
    }

    private static void testTeacherDao() {
        //目标对象
        TeacherDao target = new TeacherDao();
        //代理对象
        TeacherDao proxy = (TeacherDao) new ProxyFactory(target).getProxyInstance();
        //执行代理对象的方法
        proxy.save();
        proxy.update(1);
    }

}
